package com.cskaoyan.service;

import com.cskaoyan.bean.FeedBack;
import com.cskaoyan.bean.FeedBackExample;
import com.cskaoyan.bean.ListData;
import com.cskaoyan.mapper.FeedBackMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 杨杰
 * @version V1.0
 * @Package com.cskaoyan.service
 * @date 2020/12/5 21:37
 * @Copyright © 暂时还没有
 */
@Service
public class AdminFeedbackSeviceImp implements AdminFeedbackService{
    @Autowired
    FeedBackMapper feedBackMapper;
    @Override
    public ListData<FeedBack> adminFeedbackList(Integer page, Integer limit, String sort, String order, String username, Integer id) {

        PageHelper.startPage(page,limit);
        FeedBackExample feedBackExample = new FeedBackExample();
        feedBackExample.setOrderByClause(sort+" "+order);
        FeedBackExample.Criteria criteria = feedBackExample.createCriteria();
        if (username != null){
            criteria.andUsernameLike("%" + username + "%");
        }
        if (id != null){
            criteria.andIdEqualTo(id);
        }

        ListData<FeedBack> listData = new ListData<>();
        List<FeedBack> feedBacks = feedBackMapper.selectByExample(feedBackExample);
        listData.setItems(feedBacks);
        PageInfo pageInfo = new PageInfo(feedBacks);
        listData.setTotal((int)pageInfo.getTotal());

        return listData;
    }
}
